package com.smartleanx.module.hrm.service.companysystem;

import cn.hutool.core.collection.CollUtil;
import com.smartleanx.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.smartleanx.module.hrm.dal.dataobject.companysystem.CompanySystemDeptDO;
import com.smartleanx.module.hrm.dal.mysql.companysystemdept.CompanySystemDeptMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import static com.smartleanx.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.smartleanx.module.hrm.enums.ErrorCodeConstants.COMPANY_SYSTEM_DEPT_NOT_EXISTS;

/**
 * 学习范围（公司制度和组织架构关联表） Service 实现类
 *
 * @author 精益大师
 */
@Service
@Validated
public class CompanySystemDeptServiceImpl implements CompanySystemDeptService {

    @Resource
    private CompanySystemDeptMapper companySystemDeptMapper;

    public List<CompanySystemDeptDO> getSystemDeptList(Long id) {
        return companySystemDeptMapper.getSystemDeptList(id);
    }

    public int deleteBatchByCompanySystemID(Long id) {
        List<CompanySystemDeptDO> list = getSystemDeptList(id);
        if (CollUtil.isEmpty(list)) {
            throw exception(COMPANY_SYSTEM_DEPT_NOT_EXISTS);
        }
        return companySystemDeptMapper.deleteByCompanySystemId(id);
    }

    public Boolean insertCompanySystemDeptBatch(List<CompanySystemDeptDO> list) {
        return companySystemDeptMapper.insertBatch(list);
    }

    public int deleteByIds(Collection<?> idList) {
        return companySystemDeptMapper.deleteBatchIds(idList);
    }

    public List<CompanySystemDeptDO> getListByCompanySystemId(Collection<Long> ids) {
        if (CollUtil.isEmpty(ids)){
            return Collections.emptyList();
        }
        return companySystemDeptMapper.getListByCompanySystemId(ids);
    }

    public List<CompanySystemDeptDO> getListByDeptId(Collection<Long> ids) {
        return companySystemDeptMapper.getListByDeptId(ids);
    }


}
